package stringCount;

import java.util.Scanner;

public class StringCount {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串1：");
        String str1 = scanner.nextLine();
        System.out.println("请输入字符串2：");
        String str2 = scanner.nextLine();

        int count = 0;
        int index = 0;

        while ((index = str2.indexOf(str1, index))!= -1) {
            count++;
            index += str1.length();
        }

        System.out.println("字符串1在字符串2中出现了" + count + " 次");

        scanner.close();
    }
}
